import Foundation
import UIKit

public class ListNode {
    public var val: Int
    public var next: ListNode?
    public init(_ val: Int) {
        self.val = val
        self.next = nil
    }
}

extension ListNode {

    public static func printNode(_ node: ListNode?) {
        var head: ListNode? = node
        var log = "{ "
        while let node = head {
            log += "\(node.val)"
            if node.next != nil {
                log += " -> "
            }
            head = node.next
        }
        log += " }"
        
        print(log)
    }
}
